/*
 * This file is part of aion-unique <aion-unique.org>.
 *
 * aion-unique is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * aion-unique is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with aion-unique.  If not, see <http://www.gnu.org/licenses/>.
 */
package system.handlers.admincommands;

import com.aionemu.gameserver.configs.administration.AdminConfig;
import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.model.templates.spawn.SpawnTemplate;
import com.aionemu.gameserver.spawnengine.SpawnEngine;
import com.aionemu.gameserver.utils.PacketSendUtility;
import com.aionemu.gameserver.utils.chathandlers.AdminCommand;
import com.aionemu.gameserver.utils.chathandlers.AdminCommandChatHandler;

/**
 * @author Lyahim
 * 
 */
public class Spawn extends AdminCommand
{
	public Spawn()
	{
		super("spawn");
	}

	@Override
	public void executeCommand(Player admin, String[] params)
	{
		if (admin.getAccessLevel() < AdminConfig.COMMAND_SPAWNNPC)
		{
			PacketSendUtility.sendMessage(admin, "You dont have enough rights to execute this command");
			return;
		}
		if (params == null || params.length < 1)
		{
			PacketSendUtility.sendMessage(admin, "Syntax: //spawn <npcid>");
			return;
		}
		int npcId = 0;
		try
		{
			npcId = Integer.parseInt(params[0]);
		}
		catch (Exception e)
		{
		}
		if (npcId == 0)
		{
			PacketSendUtility.sendMessage(admin, "Bad npcId");
			return;
		}
		SpawnTemplate template = SpawnEngine.getInstance().addNewSpawn(admin.getWorldId(), admin.getInstanceId(), npcId, admin.getX(), admin.getY(),
				admin.getZ(), admin.getHeading(), 0, 0, false);
		if (template != null)
			SpawnEngine.getInstance().spawnObject(template, admin.getInstanceId());
	}

	public static void main(String[] args)
	{
		AdminCommandChatHandler.getInstance().registerAdminCommand(new Spawn());
	}
}